<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="../jquery/jquery-3.6.0.min.js"></script>
    <title>Document</title>
</head>
<body>
    <button id="q1"><</button>
        <img src="../imgs/1.jpg" alt="" width="500" id="w1" height="500"> 
    <button id="q2">></button>
</body>
<script>
    var arr = ["../imgs/1.jpg","../imgs/2.jpg","../imgs/3.jpg","../imgs/4.jpg","../imgs/5.jpg"],
        a   = 1
    $(function(){
        setInterval(() => {
            $('#w1').prop('src',`../imgs/${a}.jpg`)
            a = a==5?1:++a
            // console.log(a);
        }, 2000);
    })

    $('#q1').click(function(){
        a = a==1?5:a-1
        $('#w1').prop('src',`../imgs/${a}.jpg`)
        console.log(a);
    })

    $('#q2').click(function(){
        a = a==5?1:a+1
        $('#w1').prop('src',`../imgs/${a}.jpg`)
        console.log(a);
    })
</script>
</html>